//
//  WBNavigationController.swift
//  Weibo
//
//  Created by yinbo on 2018/2/27.
//  Copyright © 2018年 yinbo. All rights reserved.
//

import UIKit

class WBNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的bar
        navigationBar.isHidden = true 
        // Do any additional setup after loading the view.
    }
    @objc private func popToParent(){
        popViewController(animated: true)
    }
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //跟控制器不需要处理
        if childViewControllers.count>0{
            viewController.hidesBottomBarWhenPushed = true
            if let vc = viewController as?WBBaseViewController{
                var title = "返回"
                if childViewControllers.count==1{
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, target: self, action: #selector(popToParent),isBack:true)
            }
        }
        
        super.pushViewController(viewController, animated: animated)

    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
